"""Header_Information
------------------------------------
    File_Name: cores
    Author: RR9
    Date: 2024/10/11
    Description: 核心依赖项
------------------------------------
"""
from tortoise.transactions import in_transaction
from fastapi import HTTPException
from fastapi.security import OAuth2PasswordBearer
from loguru import logger

log = logger.bind(module="app")

# 数据库模型

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/v1/token")


async def transaction_manager_tortoise():
    """orm管理事物 默认数据库的全局依赖"""
    async with in_transaction():
        try:
            yield
        except Exception as e:
            log.info(str(e))
            print(str(e))
            raise HTTPException(status_code=500, detail=str(e))
